package com.gw.mapper;

import com.gw.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据邮箱查询用户
     * @param email
     * @return
     */
    @Select("select * from user where email = #{email};")
    User getByEmail(String email);

    /**
     * 用户注册
     * @param user
     */
    @Insert("insert into user " +
            "(avatar, nickname, email, password, name," +
            " phone, grades, student_id, identity, create_time) " +
            "values " +
            "(#{avatar}, #{nickname}, #{email}, #{password}, #{name}," +
            " #{phone}, #{grades}, #{studentId}, #{identity}, #{createTime})")
    void addUser(User user);

    /**
     * 根据邮箱修改用户信息
     * @param user
     */
    void updateUser(User user);

    /**
     * 根据id查头像
     * @param hostId
     * @return
     */
    @Select("select user.avatar from user where id = #{id}")
    String getAvaById(Long hostId);

    /**
     * 根据id查昵称
     * @param hostId
     * @return
     */
    @Select("select nickname from user where id = #{id};")
    String getNicById(Long hostId);

    /**
     * 通过id修改个人信息
     * @param user
     */
    void updateUserById(User user);

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getUserById(Long id);
}
